﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using System.Collections;

namespace CSharp.Libs.Misc
{
    public class DataLog : IDisposable
    {
        #region declarations
        private DataLogSQLite _dlSQLite = null;
        #endregion



        #region constructor / finalaizer
        public DataLog()
        {
            _dlSQLite = new DataLogSQLite();
            _dlSQLite.InitDb(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\DataLog.s3db");

            ArrayList al;
            al = _dlSQLite.GetLevels();
            al = _dlSQLite.GetCategories();
            al = _dlSQLite.QueryLogItems(
                strFromTime: "03.01.2013 08:24:00",
                strToTime: "03.01.2013 08:24:59",
                strLevel: "",
                strCategory: "",
                strTags: "",
                strMessageFilter: "test21");

            //DataLogItem dli = new DataLogItem()
            //{
            //    LogTime = DateTime.Now.ToString(),
            //    Category = "Testing",
            //    Level = "Information",
            //    Tags = "Debugging;Testing;Development",
            //    Message = "This is a Test"
            //};

            //_dlSQLite.SaveDataLogItem(dli);

            
        }

        #region Disposable Pattern (http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx)
        private bool _fDisposed = false;
        public void Dispose()
        {
            Dispose(true);

            // Use SupressFinalize in case a subclass 
            // of this type implements a finalizer.
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            // If you need thread safety, use a lock around these  
            // operations, as well as in your methods that use the resource. 
            if (!_fDisposed)
            {
                if (disposing)
                {
                    if (_dlSQLite != null) { _dlSQLite.Dispose(); }
                    //Console.WriteLine("Object disposed.");
                }

                // Indicate that the instance has been disposed.
                _dlSQLite = null;
                _fDisposed = true;
            }
        }
        #endregion
        #endregion


    }
}
